#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

namespace cxs
{
	class String
	{
	 public:
		String(const char* str = "")
			:
			  _str(new char[strlen(str) + 1])
			, _size(strlen(str))
			, _capacity(strlen(str) + 1)
		{
			strcpy(_str,str);
		}

		~String()
		{
			delete[] _str;
			_str = nullptr;
			_size = _capacity = 0;
		}

		String(const String& s)
		{
			this->_str=new char[strlen(s._str) + 1];
			strcpy(this->_str, s._str);
			this->_size = s._size;
			this->_capacity = s._capacity;
		}

		String& operator=(const String& s)
		{
			if (this != &s)
			{
				 delete[]_str;
				_str = nullptr;
				_str=new char[strlen(s._str) + 1];
				strcpy(_str, s._str);
				_size = s._size;
				_capacity = s._capacity;
				
			}
			return *this;

		}

		const char& operator[](size_t pos) const
		{
			if (pos < _size)
			return(_str[pos]);
		}
		
		size_t size()
		{
			return _size;
		}
		

	 private:
		char* _str;
		size_t _size;
		size_t _capacity;

	};
}
